library(devtools)
devtools::install_github("sebastianbarfort/mapDK")

library(dplyr)
library(ggplot2)
library(mapDK)

data_in <- 
  read.csv("figureS3_data.csv")

data_in$par_municipality <-  gsub("\303\270", "oe", data_in$par_municipality)
data_in$par_municipality <-  gsub("\303\205", "Aa", data_in$par_municipality)
data_in$par_municipality <-  gsub("\303\246", "ae", data_in$par_municipality)
data_in$par_municipality <-  gsub("\303\245", "aa", data_in$par_municipality)
data_in$par_municipality <-  gsub("\303\206", "Ae", data_in$par_municipality)
data_in$par_municipality <-  gsub(" Kommune", "", data_in$par_municipality)
data_in$par_municipality <-  gsub("Ringbjoebing-Skjern", "Ringkoebing-Skjern", data_in$par_municipality)

  
# Plot municipalities with data ------------------------------------

data_map <- data_in
data_map$par_municipality <-  gsub("Koebenhavns", "Koebenhavn", data_map$par_municipality)
data_map$par_municipality <-  gsub("Bornholms", "Bornholm", data_map$par_municipality)
data_map$par_municipality <-  gsub("Ringkoebing-Skjern", "Ringkoebing skjern", data_map$par_municipality)

data_map <- 
  rbind(data_map, subset(data_map, par_municipality == "Bornholm")) 
data_map$par_municipality[99] <- "Christiansoe"


data_map <- 
  data_map %>%
  mutate(in2015 = as.integer(in2015))

# 2015 --------------------------------------------------------------------

map2015 <- 
  mapDK(values = "in2015",
        id     = "par_municipality",
        data   = data_map) +
  guides(fill=guide_legend(title="")) +
  theme(legend.text = element_text(size = 14),
        legend.position = "top",
        plot.title = element_text(hjust = 0.5, size = 18)) +
  ggtitle("2015") + 
  scale_fill_continuous(guide = "legend", low = "gray", high = "black", 
                        breaks = c(0,1),
                        labels = c("Not included in data",
                                   "Included in data")) 


ggsave(map2015, filename = "FigureS3.pdf", width = 8, height = 4)
